@file:JvmName("ToastUtils")

package com.yl.androidutilscenter.utils

import android.os.Looper
import android.widget.Toast
import com.yl.androidutilscenter.base.BaseApplication

/**
 * @author
 * @description: 系统toast的使用
 * @date :2024/3/8
 * @version 1.0.0
 */
object ToastUtils {
    @JvmStatic
    fun showToast(msg: String) {
        val context = BaseApplication.getInstance()
        try {
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
        } catch (e: RuntimeException) {
            //解决在子线程中调用Toast的异常情况处理
            Looper.prepare()
            Toast.makeText(context, msg, Toast.LENGTH_SHORT).show()
            Looper.loop()
        }

    }

    @JvmStatic
    fun showToast(msgRes: Int) {
        showToast(BaseApplication.getInstance().getString(msgRes))
    }

}